<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Events
 *
 * @author pleblanc
 */
require_once 'UnitTest.php';
class EventTest extends UnitTestCase {

    public static function testAddAction(){
        self::assertTrue(Qp_Event::addAction('EventTest', 'simpleAddHook', array('EventTest','simpleAddAction'), array(5,5)));
        self::assertTrue(Qp_Event::addAction('EventTest', 'argsAddHook', array('EventTest','argsAddAction'), array(18,9)));
        self::assertTrue(Qp_Event::doAction('argsAddHook',array(3,3)));
        self::assertTrue(Qp_Event::doAction('simpleAddHook'));

    }
    public static function testAddFilter(){

        Qp_Event::addFilter('EventTest', 'simpleFilteringHook', array('EventTest','simpleFiltering'));
        Qp_Event::addFilter('EventTest', 'simpleFilteringHook', array('EventTest','simpleFiltering2'));
        Qp_Event::addFilter('EventTest', 'simpleFilteringHook', array('EventTest','simpleFiltering2'));

        self::assertTrue(Qp_Event::doFilter('simpleFilteringHook','hello') === 'hello my name is patrick');


    }
    public static function testAddFilterPriorities(){

        Qp_Event::addFilter('EventTest', 'simpleFilteringHook2', array('EventTest','simpleFiltering'),array(),2);
        Qp_Event::addFilter('EventTest', 'simpleFilteringHook2', array('EventTest','simpleFiltering2'),array(), 1);
     
        self::assertTrue(Qp_Event::doFilter('simpleFilteringHook2','hello') === 'hello patrick my name is');


    }
    public static function testAddFilterOptionalArguments(){

        Qp_Event::addFilter('EventTest', 'simpleFilteringHook3', array('EventTest','filteringWithArgs'),array(' my', ' name'),1);
        Qp_Event::addFilter('EventTest', 'simpleFilteringHook3', array('EventTest','filteringWithArgs2'),array(' is', ' patrick'), 2);

        print(Qp_Event::doFilter('simpleFilteringHook3','hello'));
        self::assertTrue(Qp_Event::doFilter('simpleFilteringHook3','hello') === 'hello my name is patrick');


    }

    public static function simpleAddAction($a ,$b){
        self::AssertTrue($a + $b == 10);
    }
    public static function argsAddAction($a ,$b, $c,$d){
        self::AssertTrue(($a + $b)/$c/$d == 3);
    }
    public static function simpleFiltering($toBeFiltered){
        return $toBeFiltered . ' my name is';
    }
    public static function simpleFiltering2($toBeFiltered){
        return $toBeFiltered . ' patrick';
    }
    public static function filteringWithArgs($toBeFiltered,$arg1, $arg2){
        return $toBeFiltered . $arg1 .$arg2;
    }
    public static function filteringWithArgs2($toBeFiltered,$arg1, $arg2){
        return $toBeFiltered . $arg1 .$arg2;
    }
    
}



?>
